package com.example.service.impl;

import com.example.mapper.EmpMapper;
import com.example.pojo.Emp;
import com.example.pojo.PageBean;
import com.example.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service  //依赖注入——把当前这个类交给IOC容器管理，变成bean对象
public class EmpServiceimpl implements EmpService {
    @Autowired
    private EmpMapper  empMapper;
//    @Override
//    public PageBean page(Integer page, Integer pageSize) {
//        Long count=empMapper.count();
//        Integer start= (page-1)*pageSize;
//        List<Emp> empList = empMapper.page(start, pageSize);
//        PageBean pageBean=new PageBean(count,empList);
//        return pageBean;
//    }
@Override
public PageBean page(Integer page, Integer pageSize,String name, Short gender,
                     LocalDate begin, LocalDate end) {
    PageHelper.startPage(page,pageSize);
    List<Emp> empList = empMapper.list(name, gender, begin, end);
    Page<Emp> p= (Page<Emp>) empList;
    PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
    return pageBean;
}

    @Override
    public void delete(Integer[] ids) {
        empMapper. delete(ids);
    }

    @Override
    public void save(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.save(emp);
    }

    @Override
    public Emp getById(Integer id) {
        return empMapper.getById(id);
    }

    @Override
    public void update(Emp emp) {
    emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }
//登录
    @Override
    public Emp login(Emp emp) {
        var login = empMapper.getByUsernameAndPassword(emp);
        return login;
    }


}
